Fix duplicate FP8 state updates during activation checkpoint recomputation#3213
Open
AlbertYang514 wants to merge 3 commits into
Open
Fix duplicate FP8 state updates during activation checkpoint recomputation#3213AlbertYang514 wants to merge 3 commits into
AlbertYang514 wants to merge 3 commits into
Conversation
…compute Signed-off-by: AlbertYang514 <201034045+AlbertYang514@users.noreply.github.com>
Signed-off-by: AlbertYang514 <201034045+AlbertYang514@users.noreply.github.com>
Contributor
Signed-off-by: AlbertYang514 <201034045+AlbertYang514@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
DelayedScalingis used with multiple Transformer Engine modules under activation checkpointing, FP8 global state update ownership is incorrectly handled during recomputation.Checkpoint recomputation introduces nested FP8 autocast scopes. These scopes can independently advance forward amax/scale state, causing one forward update per recomputed checkpoint segment instead of one update per logical forward pass.
With reentrant checkpointing, recomputed modules can also repeatedly reacquire first-module ownership. This causes backward amax reduction and scale updates to execute once per recomputed module instead of once per logical backward pass.
As a result, FP8 state may be advanced multiple times within a single logical microbatch.
Minimal reproduction
The issue reproduces using only public PyTorch and Transformer Engine APIs:
transformer_engine.pytorch.LinearDelayedScalingFormat.HYBRIDte.LinearmodulesThe reproduction does not depend on a model framework, distributed runtime, external dataset, saved checkpoint, or application-specific code.
On unmodified Transformer Engine
mainat commit70957ad5aa8337a12c254e86a6e0b7ffdbbd4b59:Expected for every configuration:
The loss, input gradient, and all weight gradients remain finite and nonzero in the minimal reproduction. The incorrect state progression therefore does not necessarily produce an immediate runtime error.
The results were reproduced across three seeds before applying the fix.
Root cause
is_first_fp8_moduleis stored in process-global FP8 state, while ownership of the corresponding update belongs to the surrounding logical FP8 autocast and checkpoint frame.During activation recomputation:
This causes:
The affected state transitions involve:
Fix
The fix makes FP8 update ownership checkpoint-frame-aware and preserves it across activation recomputation.
The implementation:
DelayedScalingstate;Linear,LayerNormLinear, andLayerNormMLP.After the change, Transformer Engine performs exactly one forward and one backward global FP8 state update for each logical microbatch.
No manual FP8 update call or application-level workaround is required.
Tests
A regression test is added at:
The tests cover:
Before the fix:
All six failures were caused by forward or backward update counts differing from
1.After the fix:
The complete six-path matrix was also run with five seeds:
Related existing tests also passed:
DelayedScaling;CurrentScaling;Linear,LayerNormLinear, andLayerNormMLPbackward tests;torch.compilecoverage;The full
tests/pytorch/test_checkpoint.pycompatibility suite was not runnable locally because the checkout did not contain its required pre-generated.ptartifacts. The affected cases exited withFileNotFoundErrorbefore entering the Transformer Engine checkpoint-loading path.Real-world impact
The issue was discovered during single-GPU pretraining of a 1.68B-parameter decoder model on a 24 GB NVIDIA GeForce RTX 5090 D v2. Reentrant activation checkpointing was required to fit the workload in device memory.
The model contained 196 Transformer Engine
Linearmodules. Before the workaround, each microbatch executed:With gradient accumulation over 64 microbatches, this resulted in:
Because FP8 amax and scale state was advanced while backward propagation was still in progress, later modules in the same backward pass could consume different state from earlier modules.
This produced execution-order-sensitive dgrad corruption. Observed examples included transitions from gradients on the order of
1e-6to values above300, and intermittent pre-clipping global gradient-norm spikes as high as629406.The affected runs continued to report finite losses, making the failure easy to miss when only loss values or post-clipping gradients were monitored.
After restoring one forward and one backward update per logical microbatch:
1/1;This workload is included only as additional impact validation. The regression tests and minimal reproduction use public Transformer Engine APIs exclusively.
Diagnostic behavior
The standard Transformer Engine debug instrumentation did not reproduce the numerical explosion in this workload.
However, enabling it reduced throughput from approximately 13.0k tokens/s to 3.2k tokens/s. It also changed quantizer execution properties and substantially altered launch timing.
The debug run therefore could not exclude an execution-order-sensitive state-management issue.
Duplicate state updates were instead confirmed using lightweight Python-side counting of the actual FP8 update calls. The counter did not:
Environment
The bookkeeping failure occurs in Transformer Engine framework state management. It has been reproduced on compute capability 12.0, but there is currently no evidence that it is specific to SM120.
Type of change
Checklist